--------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  C:\research\rfwomen\restat\create_data_rlms.log
  log type:  text
 opened on:   3 Aug 2016, 10:52:39

. 
. # delimit ;
delimiter now ;
. use c:\rlms\round5\r5hhrost;

. keep site5 family5 rural;

. sort site5 family5;

. save temphouse, replace;
(note: file temphouse.dta not found)
file temphouse.dta saved

. use c:\rlms\round5\r5inwgt;

. keep site5 family5 person5 inwgt_5;

. sort site5 family5 person5;

. save temp, replace;
file temp.dta saved

. use c:\rlms\round5\r5inwomn;

. sort site5 family5 person5;

. assert aid !=.;

. merge 1:1 site5 family5 person5 using temp;

    Result                           # of obs.
    -----------------------------------------
    not matched                             0
    matched                            11,284  (_merge==3)
    -----------------------------------------

. assert _merge==3;

. save temp, replace;
file temp.dta saved

. use temphouse;

. joinby site5 family5 using temp;

. *  Creating year of birth variable;
. gen byear5=i5birthy;

. keep if i5gender==2;
(5,124 observations deleted)

. gen inrd5=1;

. sort aid;

. assert aid !=.;

. assert aid!=aid[_n-1];

. save round5, replace;
(note: file round5.dta not found)
file round5.dta saved

. *  Round 6;
. use c:\rlms\round6\r6inwomn;

. sort site censusd family person;

. sort site censusd family person;

. ren site site6;

. save temp, replace;
file temp.dta saved

. use c:\rlms\round6\r6inwgt;

. keep site6 censusd6 family6 person6 inwgt_6;

. ren censusd6 censusd;

. ren family6 family;

. ren person6 person;

. sort site censusd family person;

. merge 1:1 site6 censusd family person using temp;

    Result                           # of obs.
    -----------------------------------------
    not matched                             3
        from master                         1  (_merge==1)
        from using                          2  (_merge==2)

    matched                            10,646  (_merge==3)
    -----------------------------------------

. keep if _merge==3;
(3 observations deleted)

. drop _merge;

. sort bid;

. assert bid !=bid[_n-1];

. *  Creating year of birth variable;
. gen byear6=i6birthy;

. keep if i6gender==2;
(4,811 observations deleted)

. keep if i6rpin94==2;
(4,916 observations deleted)

. gen inrd6=1;

. assert bid !=.;

. sort bid;

. assert bid!=bid[_n-1];

. save round6, replace;
(note: file round6.dta not found)
file round6.dta saved

. *  Round 7;
. use c:\rlms\round7\r7inwomn;

. sort site7 censusd7 family7 person7;

. save temp, replace;
file temp.dta saved

. use c:\rlms\round7\r7inwork;

. keep site7 censusd7 family7 person7 i7birthy;

. ;
. sort site7 censusd7 family7 person7;

. save temp2, replace;
file temp2.dta saved

. use c:\rlms\round7\r7inwgt;

. keep site7 censusd7 family7 person7 inwgt_7;

. sort site7 censusd7 family7 person7;

. drop if site7==133 & censusd7==0 & family7==51 & person7==7;
(1 observation deleted)

. merge 1:1 site7 censusd7 family7 person7 using temp;

    Result                           # of obs.
    -----------------------------------------
    not matched                             1
        from master                         0  (_merge==1)
        from using                          1  (_merge==2)

    matched                            10,464  (_merge==3)
    -----------------------------------------

. keep if _merge==3;
(1 observation deleted)

. drop _merge;

. sort site7 censusd7 family7 person7;

. merge 1:1 site7 censusd7 family7 person7 using temp2;

    Result                           # of obs.
    -----------------------------------------
    not matched                             1
        from master                         0  (_merge==1)
        from using                          1  (_merge==2)

    matched                            10,464  (_merge==3)
    -----------------------------------------

. keep if _merge==3;
(1 observation deleted)

. drop _merge;

. *  Creating year of birth variable;
. gen byear7=i7birthy;

. keep if i7rpinbf==3;
(9,175 observations deleted)

. keep if i7gender==2;
(627 observations deleted)

. gen inrd7=1;

. sort cid;

. assert cid !=.;

. assert cid !=cid[_n-1];

. save round7, replace;
(note: file round7.dta not found)
file round7.dta saved

. *  Round 8;
. use c:\rlms\round8\r8inwomn;

. sort site8 censusd8 family8 person8;

. save temp, replace;
file temp.dta saved

. use c:\rlms\round8\r8inwgt;

. keep site8 censusd8 family8 person8 inwgt_8 did;

. sort site8 censusd8 family8 person8;

. merge 1:1 site8 censusd8 family8 person8 using temp;

    Result                           # of obs.
    -----------------------------------------
    not matched                         5,741
        from master                     5,741  (_merge==1)
        from using                          0  (_merge==2)

    matched                             4,936  (_merge==3)
    -----------------------------------------

. keep if _merge==3;
(5,741 observations deleted)

. drop _merge;

. *  Creating year of birth variable;
. gen byear8=i8birthy;

. keep if i8rpinbf==4;
(4,221 observations deleted)

. keep if i8gender==2;
(0 observations deleted)

. gen inrd8=1;

. sort did;

. assert did !=.;

. assert did!=did[_n-1];

. save round8, replace;
(note: file round8.dta not found)
file round8.dta saved

. *  Appending rounds;
. use round5;

. append using round6;

. append using round7;

. append using round8;

. gen age94=1994-byear5 if inrd5==1;
(2,296 missing values generated)

. gen age95=1995-byear6 if inrd6==1;
(7,537 missing values generated)

. gen age96=1996-byear7 if inrd7==1;
(7,794 missing values generated)

. gen age98=1998-byear8 if inrd8==1;
(7,741 missing values generated)

. gen byear=byear5;
(2,296 missing values generated)

. replace byear=byear6 if byear==.;
(919 real changes made)

. replace byear=byear7 if byear==.;
(662 real changes made)

. replace byear=byear8 if byear==.;
(715 real changes made)

. gen site=site5;
(2,296 missing values generated)

. replace site=site6 if site==.;
(919 real changes made)

. replace site=site7 if site==.;
(662 real changes made)

. replace site=site8 if site==.;
(715 real changes made)

. gen psu=.;
(8,456 missing values generated)

. replace psu=1 if site==141 & psu==.;
(381 real changes made)

. replace psu=2 if site >=138 & site <=140 & psu==.;
(513 real changes made)

. replace psu=3 if site>=142 & site <=160 & psu==.;
(399 real changes made)

. replace psu=4 if site==105 & psu==.;
(194 real changes made)

. replace psu=5 if site==89 & psu==. | site==90 & psu==. | site==91 & psu==.;
(196 real changes made)

. replace psu=6 if site >=1 & site <=8 & psu==.;
(181 real changes made)

. replace psu=7 if site==135 & psu==.;
(216 real changes made)

. replace psu=8 if site==67 & psu==. | site==68 & psu==. | site==69 & psu==.;
(160 real changes made)

. replace psu=9 if site==136 & psu==.;
(188 real changes made)

. replace psu=10 if site>=14 & site <=32 & psu==.;
(138 real changes made)

. replace psu=11 if site==116 & psu==.;
(196 real changes made)

. replace psu=12 if site>=48 & site <=51 & psu==.;
(196 real changes made)

. replace psu=13 if site>=117 & site <=128 & psu==.;
(173 real changes made)

. replace psu=14 if site==72 & psu==.;
(236 real changes made)

. replace psu=15 if site>=33 & site <=38 & psu==.;
(176 real changes made)

. replace psu=16 if site==45 & psu==.;
(208 real changes made)

. replace psu=17 if site==70 & psu==.;
(213 real changes made)

. replace psu=18 if site>=100 & site <=104 & psu==.;
(197 real changes made)

. replace psu=19 if site>=39 & site <=44 & psu==.;
(197 real changes made)

. replace psu=20 if site>=77 & site <=83 & psu==.;
(298 real changes made)

. replace psu=21 if site==137 & psu==.;
(248 real changes made)

. replace psu=22 if site==9 & psu==.;
(174 real changes made)

. replace psu=23 if site>=52 & site <=57 & psu==.;
(200 real changes made)

. replace psu=24 if site>=129 & site <=134 & psu==.;
(215 real changes made)

. replace psu=25 if site==106 & psu==.;
(189 real changes made)

. replace psu=26 if site==46 & psu==.;
(224 real changes made)

. replace psu=27 if site==10 & psu==. | site==11 & psu==.;
(201 real changes made)

. replace psu=28 if site==47 & psu==.;
(237 real changes made)

. replace psu=29 if site==12 & psu==. | site==13 & psu==.;
(194 real changes made)

. replace psu=30 if site>=107 & site <=115 & psu==.;
(181 real changes made)

. replace psu=31 if site==71 & psu==.;
(202 real changes made)

. replace psu=32 if site>=86 & site <=88 & psu==.;
(223 real changes made)

. replace psu=33 if site==84 | site==85 & psu==.;
(214 real changes made)

. replace psu=34 if site >=58 & site <=65 & psu==.;
(205 real changes made)

. replace psu=35 if site==66 & psu==.;
(204 real changes made)

. replace psu=36 if site==92 & psu==.;
(302 real changes made)

. replace psu=37 if site>=73 & site <=76 & psu==.;
(202 real changes made)

. replace psu=38 if site>=93 & site <=99 & psu==.;
(185 real changes made)

. assert psu !=0 & psu !=.;

. *  Creating oblast dummy variables;
. gen regno=0;

. replace regno=7 if site==141;
(381 real changes made)

. replace regno=16 if site==138 | site==139 | site==140;
(513 real changes made)

. replace regno=17 if site>=142 & site<=160;
(399 real changes made)

. replace regno=2 if site==105 | site==89 | site==90 | site==91;
(390 real changes made)

. replace regno=8 if site >=1 & site<=8;
(181 real changes made)

. replace regno=20 if site==135;
(216 real changes made)

. replace regno=21 if site==67 | site==68 | site==69;
(160 real changes made)

. replace regno=22 if site==136;
(188 real changes made)

. replace regno=14 if site>=14 & site<=32;
(138 real changes made)

. replace regno=28 if site==116;
(196 real changes made)

. replace regno=26 if site>=48 & site<=51;
(196 real changes made)

. replace regno=38 if site>=117 & site<=128;
(173 real changes made)

. replace regno=32 if site==72;
(236 real changes made)

. replace regno=33 if site>=33 & site<=38;
(176 real changes made)

. replace regno=35 if site==45;
(208 real changes made)

. replace regno=40 if site==70 | site>=100 & site<=104;
(410 real changes made)

. replace regno=37 if site>=39 & site<=44;
(197 real changes made)

. replace regno=44 if site>=77 & site<=83;
(298 real changes made)

. replace regno=51 if site==137;
(248 real changes made)

. replace regno=49 if site==9 | site>=129 & site<=134;
(389 real changes made)

. replace regno=50 if site>=52 & site<=57;
(200 real changes made)

. replace regno=59 if site==106;
(189 real changes made)

. replace regno=54 if site==46;
(224 real changes made)

. replace regno=53 if site==10 | site==11;
(201 real changes made)

. replace regno=55 if site==47;
(237 real changes made)

. replace regno=56 if site==12 | site==13;
(194 real changes made)

. replace regno=59 if site>=107 & site<=115;
(181 real changes made)

. replace regno=65 if site==71;
(202 real changes made)

. replace regno=67 if site>=86 & site<=88;
(223 real changes made)

. replace regno=61 if site==84 | site==85;
(214 real changes made)

. replace regno=61 if site>=58 & site<=65;
(205 real changes made)

. replace regno=72 if site==66;
(204 real changes made)

. replace regno=82 if site==92;
(302 real changes made)

. replace regno=72 if site>=73 & site<=76;
(202 real changes made)

. replace regno=84 if site>=93 & site<=99;
(185 real changes made)

. assert regno !=.;

. *  Only have rural information for Round 5;
. *  Using codes for Round5 to assign urban/rural for other rounds;
. replace rural=0 if rural==1 | rural==2;
(4,624 real changes made)

. replace rural=1 if rural==3;
(1,536 real changes made)

. replace rural=0 if regno==16 & rural==.;
(118 real changes made)

. replace rural=0 if regno==7 & rural==.;
(122 real changes made)

. replace rural=1 if site==144 & rural==.;
(5 real changes made)

. replace rural=1 if site==151 & rural==.;
(5 real changes made)

. replace rural=1 if site==152 & rural==.;
(7 real changes made)

. replace rural=1 if site==158 & rural==.;
(2 real changes made)

. replace rural=1 if site==90 & rural==.;
(5 real changes made)

. replace rural=1 if site==91 & rural==.;
(1 real change made)

. replace rural=1 if site>=2 & site<=8 & rural==.;
(18 real changes made)

. replace rural=1 if site==68 & rural==.;
(1 real change made)

. replace rural=1 if site==69 & rural==.;
(3 real changes made)

. replace rural=1 if site>=14 & site<=32 & rural==.;
(12 real changes made)

. replace rural=1 if site==49 & rural==.;
(3 real changes made)

. replace rural=1 if site==50 & rural==.;
(8 real changes made)

. replace rural=1 if site>=118 & site<=128 & rural==.;
(21 real changes made)

. replace rural=1 if site>=34 & site<=38 & rural==.;
(8 real changes made)

. replace rural=1 if site==101 & rural==.;
(11 real changes made)

. replace rural=1 if site==102 & rural==.;
(1 real change made)

. replace rural=1 if site>=40 & site<=44 & rural==.;
(10 real changes made)

. replace rural=1 if site>=78 & site<=83 & rural==.;
(43 real changes made)

. replace rural=1 if site>=53 & site<=57 & rural==.;
(22 real changes made)

. replace rural=1 if site>=129 & site<=137 & rural==.;
(245 real changes made)

. replace rural=1 if site==11 & rural==.;
(2 real changes made)

. replace rural=1 if site==13 & rural==.;
(2 real changes made)

. replace rural=1 if site>=107 & site<=115 & rural==.;
(29 real changes made)

. replace rural=1 if site==85 & rural==.;
(3 real changes made)

. replace rural=1 if site>=58 & site<=65 & rural==.;
(52 real changes made)

. replace rural=1 if site>=74 & site<=76 & rural==.;
(8 real changes made)

. replace rural=1 if site>=93 & site<=99 & rural==.;
(45 real changes made)

. replace rural=0 if rural==.;
(1,484 real changes made)

. *  Merging in oblast and republic sex ratios by year of birth;
. replace regno=66 if regno==67;
(223 real changes made)

. sort regno byear;

. drop _merge;

. merge m:1 regno byear using sexratios_ussr;

    Result                           # of obs.
    -----------------------------------------
    not matched                        11,056
        from master                     6,366  (_merge==1)
        from using                      4,690  (_merge==2)

    matched                             2,090  (_merge==3)
    -----------------------------------------

. keep if _merge==3;
(11,056 observations deleted)

. drop _merge;

. drop if inrd5==. & inrd6==. & inrd7==. & inrd8==. ;
(0 observations deleted)

. drop if sr10a==.;
(0 observations deleted)

. keep if byear >=1915 & byear <=1941;
(0 observations deleted)

. gen age=age94;
(397 missing values generated)

. replace age=age95 if inrd6==1;
(158 real changes made)

. replace age=age96 if inrd7==1;
(104 real changes made)

. replace age=age98 if inrd8==1;
(135 real changes made)

. *  Number of births;
. replace i6totbir=. if i6totbir==99;
(1 real change made, 1 to missing)

. replace i5totbir=0 if i5hadbab==2;
(54 real changes made)

. replace i6totbir=0 if i6hadbab==2;
(3 real changes made)

. replace i7totbir=0 if i7hadbab==2;
(3 real changes made)

. replace i8totbir=0 if i8hadbab==2;
(4 real changes made)

. replace i5totbir=1 if i5hadbab==1 & i5totbir==.;
(19 real changes made)

. replace i6totbir=1 if i6hadbab==1 & i6totbir==.;
(1 real change made)

. replace i7totbir=1 if i7hadbab==1 & i7totbir==.;
(0 real changes made)

. replace i8totbir=1 if i8hadbab==1 & i8totbir==.;
(0 real changes made)

. *  Child death variable only in Round 5;
. *  Have to compute it for Rounds 6-8;
. egen bornliv6=rowtotal(i6bbaliv *i6gbaliv) if inrd6==1;
(1932 missing values generated)

. gen i6chddie=1 if i6totbir > bornliv6 & inrd6==1;
(2,054 missing values generated)

. replace i6chddie=0 if i6totbir==bornliv6 & inrd6==1;
(121 real changes made)

. egen bornliv7=rowtotal(i7bbaliv i7gbaliv) if inrd7==1;
(1986 missing values generated)

. gen i7chddie=1 if i7totbir > bornliv7 & inrd7==1;
(2,077 missing values generated)

. replace i7chddie=0 if i7totbir==bornliv7 & inrd7==1;
(91 real changes made)

. egen bornliv8=rowtotal(i8bbaliv i8gbaliv) if inrd8==1;
(1955 missing values generated)

. gen i8chddie=1 if i8totbir > bornliv8 & inrd8==1;
(2,077 missing values generated)

. replace i8chddie=0 if i7totbir==bornliv7 & inrd7==1;
(91 real changes made)

. replace i5totbir=1 if i5chddie==1 & i5totbir==.;
(0 real changes made)

. replace i6totbir=1 if i6chddie==1 & i6totbir==.;
(35 real changes made)

. replace i7totbir=1 if i7chddie==1 & i7totbir==.;
(13 real changes made)

. replace i8totbir=1 if i8chddie==1 & i8totbir==.;
(13 real changes made)

. gen totbir=i5totbir if inrd5==1;
(504 missing values generated)

. replace totbir=i6totbir if inrd6==1;
(158 real changes made)

. replace totbir=i7totbir if inrd7==1;
(104 real changes made)

. replace totbir=i8totbir if inrd8==1;
(135 real changes made)

. count if totbir==.;
  107

. *  Abortions;
. *  Have you ever had an abortion;
. *  1  yes  2 no;
. gen everabo=.;
(2,090 missing values generated)

. replace everabo=1 if i5evrabo==1 | i6evrabo==1 | i7evrabo==1 | i8evrabo==1;
(1,412 real changes made)

. replace everabo=0 if i5evrabo==2 | i6evrabo==2 | i7evrabo==2 | i8evrabo==2;
(494 real changes made)

. tab everabo;

    everabo |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |        494       25.92       25.92
          1 |      1,412       74.08      100.00
------------+-----------------------------------
      Total |      1,906      100.00

. *  How many abortions in all have you had?;
. assert i5numabo != 97 & i5numabo !=98;

. assert i6numabo != 97 & i6numabo !=98;

. assert i7numabo != 97 & i7numabo !=98;

. assert i8numabo != 97 & i8numabo !=98;

. gen numabo=.;
(2,090 missing values generated)

. replace numabo=i5numabo if inrd5==1;
(1,152 real changes made)

. replace numabo=i6numabo if inrd6==1;
(88 real changes made)

. replace numabo=i7numabo if inrd7==1;
(65 real changes made, 4 to missing)

. replace numabo=i8numabo if inrd8==1;
(71 real changes made)

. assert numabo==0 | numabo==. if everabo==0;

. replace numabo=0 if everabo==0;
(494 real changes made)

. replace numabo=1 if everabo==1 & numabo==.;
(36 real changes made)

. replace everabo=1 if numabo >=1 & numabo !=.;
(0 real changes made)

. gen popm=popmu+popmr;
(237 missing values generated)

. replace popm=popmu if regno==7 | regno==16;
(237 real changes made)

. gen lnpopm=log(popm);

. gen yr94=0;

. replace yr94=1 if inrd5==1;
(1,693 real changes made)

. gen yr95=0;

. replace yr95=1 if inrd6==1;
(158 real changes made)

. gen yr96=0;

. replace yr96=1 if inrd7==1;
(104 real changes made)

. gen yr98=0;

. replace yr98=1 if inrd8==1;
(135 real changes made)

. gen inwgt=.;
(2,090 missing values generated)

. replace inwgt=inwgt_5;
(1,693 real changes made)

. replace inwgt=inwgt_6 if inwgt==.;
(158 real changes made)

. replace inwgt=inwgt_7 if inwgt==.;
(104 real changes made)

. replace inwgt=inwgt_8 if inwgt==.;
(135 real changes made)

. save data_rlms, replace;
file data_rlms.dta saved

. log close;
      name:  <unnamed>
       log:  C:\research\rfwomen\restat\create_data_rlms.log
  log type:  text
 closed on:   3 Aug 2016, 10:52:40
--------------------------------------------------------------------------------------------------------------------
